package scribble;

import java.awt.*;
import java.awt.event.*;
import java.util.EventListener;
import java.util.Vector;

import javax.swing.*;

public class Doodle extends JApplet{
	protected  ScribbleCanvas canvas;
	protected EventListener listener;
	protected boolean isApplet = false;
	
//	private JTextField textPass;
//	private JPanel panelTextPass;
	
	protected static int frameW= 1200;
	protected static int frameH= 600;
	
	protected PasswordGen password;
	
	public Doodle(boolean isApplet){
		
		this.isApplet = isApplet;
		getContentPane().setLayout(new BorderLayout());
		getContentPane().add(makeCanvas(), BorderLayout.CENTER);
		
		makePassword();
		listener = makeCanvasListener(canvas);
		canvas.addMouseListener((MouseListener) listener);
		canvas.addMouseMotionListener((MouseMotionListener) listener);
		
	}
	public Doodle(){
		//invoked as an applet
		this(true);
	}
	
	protected Component makeCanvas(){
		canvas = new ScribbleCanvas();
		return canvas;
	}
	
	
	protected void makePassword(){
		password = new PasswordGen(canvas, frameW, frameH);
	}
	
	
	protected EventListener makeCanvasListener(ScribbleCanvas canvas) {
		return new ScribbleCanvasListener(canvas, password);
	}
		
//	public static void main(String[] args){
//		JFrame frame = new JFrame();
//		frame.setTitle("Scribble Pad");
//		frame.getContentPane().setLayout(new BorderLayout());
//		frame.getContentPane().add(new Doodle (false), BorderLayout.CENTER);
//		frame.addWindowListener(new AppCloser());
//		frame.pack();
//		frame.setSize(frameW, frameH);
//		frame.show();
//	}
	
	static class AppCloser extends WindowAdapter{
		public void windowClosing(WindowEvent e){
			System.exit(0);
		}
	}
	
}
